package com.gugee.ins.data.collector.bloggerlocation.listener;

import com.gugee.ins.data.collector.bloggerlocation.config.InsBloggerLocationConfig;
import com.gugee.ins.data.collector.bloggerlocation.service.InsBloggerLocationService;
import com.gugee.ins.data.common.consumer.AbstractGugeeConsumerHandler;
import com.gugee.ins.data.common.msg.InsBloggerMessage;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.kafka.support.Acknowledgment;
import org.springframework.stereotype.Component;

import java.util.List;


/**
 * insBloggerLocation Listener
 *
 * @author Huangxin
 */
@Component
@Slf4j
public class InsBloggerLocationListener {

    /**
     * InsBloggerFollowingConfig
     */
    @Autowired
    private InsBloggerLocationConfig insBloggerLocationConfig;

    /**
     * insBloggerFollowerService
     */
    @Autowired
    private InsBloggerLocationService insBloggerLocationService;

    private InsBloggerLocationHandler collectHandler = new InsBloggerLocationHandler();

    /**
     * 监听任务,完成活跃粉丝的关注列表采集
     * @param messages
     * @param ack
     */
    @KafkaListener(id="${kafka.consumer.group.insBloggerLocation.id}",
            topics = {"${kafka.topics.insBloggerLocation.online}","${kafka.topics.insBloggerLocation.priority}"},
            containerFactory = "factoryInsBloggerLocationAck")
    public void bloggerMainCollect(List<InsBloggerMessage> messages, Acknowledgment ack) {
        collectHandler.handle("InsBloggerLocation",messages, insBloggerLocationConfig.getAcceptInsBloggerLocationMsgTimeMinRange(),ack);
    }

    class InsBloggerLocationHandler extends AbstractGugeeConsumerHandler<InsBloggerMessage>{
        @Override
        public void dealMsg(List<InsBloggerMessage> messages) {
            insBloggerLocationService.handleLocationCollect(messages);
        }
    }
}
